/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.mwas.proteana.annotations;

import java.text.Annotation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import pl.mwas.proteana.geneontology.GOTermDb;

/**
 *
 * @author mateusz.was
 */
public class AnnotationDb {
    private final HashMap<String, ArrayList<GOAnnotation>> annotationMap;

    public AnnotationDb() {
        this.annotationMap = new HashMap<>();
    }

    public AnnotationDb(ArrayList<GOAnnotation> annotationList) {
        this();
        for(GOAnnotation annotation : annotationList) {
            addAnnotation(annotation);
        }
    }
    
    public void addAnnotation(GOAnnotation annotation) {
        String annotId = annotation.getDbId();
        ArrayList<GOAnnotation> annotArrayList;
        if(!annotationMap.containsKey(annotId)) {
            annotArrayList = new ArrayList<>();
            annotArrayList.add(annotation);
            annotationMap.put(annotId, annotArrayList);
        } else {
            annotArrayList = annotationMap.get(annotId);
            annotArrayList.add(annotation);
            annotationMap.remove(annotId);
            annotationMap.put(annotId, annotArrayList);
        }
    }
    
    public ArrayList<GOAnnotation> getAnnotationsForId(String annotId) {
        return annotationMap.get(annotId);
    }
    
    public void addGoTermsToAnnotations(GOTermDb db) {
        for(Map.Entry<String, ArrayList<GOAnnotation>> entry : annotationMap.entrySet()) {
            for(GOAnnotation annot : entry.getValue()) {
                annot.linkToGOTerm(db);
            }
        }
    }
    
}
